<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp"%>
<html>
<head>
<title>还款申请管理</title>
<link rel="stylesheet" type="text/css" href="${ctx}/styles/ec/ecside_style.css" />
<%@include file="/common/meta.jsp"%>
<%@include file="/common/validator.jsp"%>
<script type="text/javascript">
function showBorrowInfo() {
  var url = '${ctx}/borrow/selectBorrowIndex.do?type=radio';
  var styles = "dialogWidth:585px; dialogHeight:430px; status:no; scroll:no; help:no";
  var selectedBorrows = window.showModalDialog(url, null, styles);
	var borrowId = selectedBorrows.ids.substring(0, selectedBorrows.ids.length - 1);
	var borrowAmount = selectedBorrows.borrowAmounts.substring(0, selectedBorrows.borrowAmounts.length - 1);
	var rePayAmount = selectedBorrows.rePayAmounts.substring(0, selectedBorrows.rePayAmounts.length - 1);
	document.getElementById("borrowId").value = borrowId;
	document.getElementById("borrowAmount").value = borrowAmount;
	document.getElementById("rePayAmount").value = rePayAmount;
	
	var amount = Number(borrowAmount) - Number(rePayAmount);
    amount = Math.round(amount*100)/100;
	document.getElementById("noRePayAmount").value = amount;	
	document.getElementById("amount").value = amount;
}
</script>
</head>
<body>
<div class="x-panel" style="width: 100%">
<div class="x-panel-header">还款申请管理</div>
<div><%@ include file="/common/messages.jsp"%></div>
<div align="center" style="width: 100%">
<s:form action="save.do" id="save" method="post">
	<s:hidden name="model.id" />
	<table width="75%" border="1" align="center" cellpadding="0" cellspacing="0" style="border-collapse: collapse; border-left-width:0px; border-top-width:0px; padding: 4px 2px; margin-top: 10px;">
	<tbody id="tbody">
		<tr height="20" style="padding: 8px 2px;"> 
           <td align="center" colspan="7"><font size="3">还款单</font></td>
        </tr>	
		<tr height="20" style="padding: 10px 2px; padding-left: 18px;"> 
           <td align="left" colspan="7">还款部门：
           ${model.dept.name}
           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;还款人：<stc:username></stc:username>
           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;还款时间：<s:date name="model.createDate" format="yyyy-MM-dd HH:mm"/>
           </td>
        </tr>	
        <tr>
           <td align="right" width="80">还款单号：</td>
           <td align="left" colspan="6">
           		<s:textfield  id="singleNo" name="model.singleNo" cssClass="required" cssStyle="width:140px; border:1px dotted #808080;" ></s:textfield >
           		<font color="red">*</font>
			</td>
        </tr>         
        <tr>
           <td align="right" width="80">摘&nbsp;&nbsp;&nbsp;&nbsp;要：</td>
           <td align="left" colspan="6">
           		<s:textfield  id="title" name="model.title" cssClass="required" cssStyle="width:452px; border:1px dotted #808080;"></s:textfield >
           		<font color="red">*</font>
			</td>
        </tr>  
              
        <tr>
           <td align="right">借款金额：</td>
           <td align="left" width="140">
                <s:hidden id="borrowId" name="borrowId" /> 
           		<s:textfield  id="borrowAmount" name="model.borrow.amount"  cssClass="required" cssStyle="width:80px;color:#808080; border:1px dotted #808080;" readonly="true"></s:textfield >
           		<font color="red">*</font>
			</td>
           <td align="right" width="90">已还金额：</td>
           <td align="left" >
           		<s:textfield id="rePayAmount" name="model.borrow.rePayAmount"  cssStyle="width:65px;color:#808080;border:0" readonly="true"></s:textfield >
		   </td>	
           <td align="right" width="90">未还金额：</td>
           <td> 
           		<s:textfield id="noRePayAmount" name="noRePayAmount"  cssStyle="width:65px;color:#808080;border:0" readonly="true"></s:textfield >
           </td>
           <td align="left" width="110">
              <input type="button" class="button" onclick="showBorrowInfo()" value="选择借款单" title="弹出的借款单列表中,双击某一行可确定其借款信息" style="width: 80px;"/>
           </td>					
        </tr>
        
        <tr>
           <td align="right">还款金额：</td>
           <td align="left" colspan="6">
           		<s:textfield  id="amount" name="model.amount" cssClass="required" onkeyup="yzsz(this)" cssStyle="width:80px; border:1px dotted #808080;"></s:textfield >
           		<font color="red">*</font>
			</td>
        </tr>
        
	
		<tr>
			<td align="right">备&nbsp;&nbsp;&nbsp;&nbsp;注：</td>
			<td align="left" colspan="7" style="padding-left: 0px;">
				<textarea id="descn" name="model.descn" style="width: 452px; border:1px dotted #808080;" rows="4" >${model.descn}</textarea>
			</td>
		</tr>
        	
   </tbody>
	</table>
	<table width="600px" style="margin-bottom: 10px;">
		<tr>
			<td style="text-align: center;">
			  <s:submit value="保存" 	cssClass="button" /> 
			  &nbsp;&nbsp;
			  <s:reset value="重置" cssClass="button" />
			</td>
		</tr>
	</table>
</s:form>
</div>
</div>

<script type="text/javascript">
$(document).ready(function(){
	$("#title").focus();
});

$('#amount').keydown(function(e){
	e = window.event || e;
	if(e.keyCode==13 || e.keyCode == 9){
		e.keyCode=9;
	}
});

$(document).ready(function() {
	$("#save").validate();
});

/**
 * 验证借款金额输入的必须是数字
 */
function yzsz(amount){
	if(isNaN(amount.value)||amount.value-0<0){
		alert("请输入数字并且大于0！");
		amount.value="";
		amount.focus();
		return;
	}
	var borrowAmount = document.getElementById("borrowAmount").value ;
	var rePayAmount = document.getElementById("rePayAmount").value ;
	var needPayAmount = borrowAmount - rePayAmount;
	if (amount.value > needPayAmount) {
		alert("您输入的还款金额已超过未还款的金额【" + needPayAmount  + "】，不允许输入！");
		amount.value="";
		amount.focus();
		return;	
	}
}
</script>
</body>
</html>